package org.wattdepot.cli.command;

import static org.junit.Assert.assertTrue;
import org.junit.Test;

/**
 * Tests the listTotal with various inputs for correct outputs.
 * 
 * @author Alex Kan and Kelvin Green
 * @version 2.0
 */
public class TestWattDepotListTotal {

  WattDepotCommand commandInstance;
  String[] commandArray;
  String userInput;

  /**
   * Test WattDepotListTotal for 2 correct outputs and errors on 2 inputs.
   * 
   * Test (correct) total energy generated SIM_WAIAU day 2009-11-15 sampling-interval 30: Energy
   * Generated: 38284 Test (correct) total energy generated SIM_WAIAU_8 day 2009-11-15
   * sampling-interval 30: Energy Generated: 17164 Test (error) total energy generated SIM_WAIAU_8
   * day 2009-11-15 sampling-interval 30 1: total [carbon|energy] generated {source} day {day}
   * sampling-interval {minutes} Test (error) total carbon generated SIM_WAIAU_8 day 2009/11-15
   * sampling-interval 30: Not a valid day.
   */
  @Test
  public void testListTotal() {
    WattDepotCommand.connect("http://server.wattdepot.org:8182/wattdepot/");
    commandInstance = new WattDepotListTotalCommand();
    userInput = "total energy generated SIM_WAIAU day 2009-11-15 sampling-interval 30";
    commandArray = userInput.split(" ");
    assertTrue("Check for total energy generated for SIM_WAIAU", commandInstance.doCommand(
        commandArray).contains("Energy Generated: 38284"));

    userInput = "total energy generated SIM_WAIAU_8 day 2009-11-15 sampling-interval 30";
    commandArray = userInput.split(" ");
    assertTrue("Check for total energy generated for SIM_WAIAU_8", commandInstance.doCommand(
        commandArray).contains("Energy Generated: 17164"));

    userInput = "total energy generated SIM_WAIAU_8 day 2009-11-15 sampling-interval 30 1";
    commandArray = userInput.split(" ");
    assertTrue("Check for error", commandInstance.doCommand(commandArray).contains(
        "total [carbon|energy] generated {source} day {day} sampling-interval {minutes}"));

    userInput = "total carbon generated SIM_WAIAU_8 day 2009/11-15 sampling-interval 30";
    commandArray = userInput.split(" ");
    assertTrue("Check for error", commandInstance.doCommand(commandArray).contains(
        "Not a valid day."));

  }

}
